﻿using System;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ContactCenter.Core.ObjectModel;
using ContactCenter.UI.Web.Controllers;
using StructureMap;

namespace ContactCenter.UI.Web.Extensibility
{
    public static class StructureMapDependencyContextExtensions
    {
        public static IContainer RunBootstrapperJobs(this IContainer container)
        {
            var jobs = container.GetAllInstances<IBootstrapperJob>().OrderBy(x=>x.Position);

            foreach (var job in jobs)
            {
                job.Execute();
            }

            return container;
        }

        public static IContainer InitHttpModules(this IContainer container, Action<IHttpModule> action)
        {
            var modules = container.GetAllInstances<IHttpModule>();

            foreach (var module in modules)
            {
                action(module);
            }

            return container;
        }
    }
}